package com.ftx.controller.test.annotation.importTest;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * Created by fengtingxin on 2020/4/14.
 */
public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    /**
     *
     * @param importingClassMetadata 当前类的注解信息
     * @param registry bean定义的注册类
     *                 把所有需要添加到容器中的bean，可以调用registry.registerBeanDefinition 的方法，手动注册
     */
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        System.out.println("this is  MyImportBeanDefinitionRegistrar");
        if (registry.containsBeanDefinition("com.ftx.controller.test.annotation.importTest.Red") &&  registry.containsBeanDefinition("com.ftx.controller.test.annotation.importTest.Blue")){
            RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(Yellow.class);
            registry.registerBeanDefinition("Yellow",rootBeanDefinition);
        }
    }
}
